﻿namespace GBALib.System
{
    public class HighPerformanceTimer
    {
        #region Member Variables
        private long startTime = 0;
        #endregion

        public HighPerformanceTimer()
        {
        }

        #region Methods
        public void Start()
        {
            // Record when the timer was started.
            this.startTime = HighPerformanceTimer.Counter;
        }
        #endregion

        #region Static Properties
        private static long frequency;

        static HighPerformanceTimer()
        {
            HighPerformanceTimer.frequency = 1000;
        }

        /// <summary>
        /// Gets the frequency that this HighPerformanceTimer performs at.
        /// </summary>
        public static long Frequency => HighPerformanceTimer.frequency;

        /// <summary>
        /// Gets the current system ticks.
        /// </summary>
        public static long Counter => DateTime.Now.Millisecond;
        #endregion

        #region Properties
        /// <summary>
        /// Gets the tick count of when this HighPerformanceTimer was started.
        /// </summary>
        public long StartTime => this.startTime;

        public long Elapsed => HighPerformanceTimer.Counter - this.startTime;

        public double ElapsedSeconds => ((double)this.Elapsed) / ((double)HighPerformanceTimer.Frequency);
        #endregion
    }
}
